//
//  HEMineOrderCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/10/16.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEMineOrderCell.h"

@interface HEMineOrderCell ()

@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UIScrollView *manContent;


@end

@implementation HEMineOrderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    // 标题
    _titleLb = [UILabel new];
    _titleLb.text = @"我的订单";
    [self.contentView addSubview:_titleLb];
    _titleLb.font = DYFont(21);
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
         make.left.equalTo(self.contentView).mas_offset(15);
         make.right.equalTo(self.contentView).mas_offset(-15);
     }];
    
    // 
    _manContent = [[UIScrollView alloc] init];
    _manContent.scrollEnabled = YES;
    _manContent.showsVerticalScrollIndicator = NO;
    _manContent.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:_manContent];

    [_manContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
         make.left.equalTo(self.contentView).mas_offset(10);
         make.right.equalTo(self.contentView).mas_offset(-10);
         make.bottom.equalTo(self.contentView).mas_offset(-5);
     }];
    
    NSArray *manImgList = @[
                            @{@"name":@"护理订单", @"icon":@"my_order_all_icon"},
//                            @{@"name":@"购物车", @"icon":@"my_shop_car_icon"},
                             @{@"name":@"全部订单", @"icon":@"my_order_all_icon"},
                             @{@"name":@"待付款", @"icon":@"my_wait_pay_icon"},
                             @{@"name":@"待发货", @"icon":@"my_wait_sent_icon"},
                             @{@"name":@"待收货", @"icon":@"my_wait_receive_icon"},
                             @{@"name":@"待评价", @"icon":@"my_wait_comment_icon"},
                             @{@"name":@"退款/售后", @"icon":@"my_return_apply_icon"}];
    NSMutableArray *manArr = [NSMutableArray array];
            
    for (int i = 0; i < manImgList.count; i++) {
        
        NSDictionary *img = manImgList[i];

        // NSDictionary *img in manImgList
        QMUIButton *btn = [[QMUIButton alloc] init];
        btn.imagePosition = QMUIButtonImagePositionTop;// 将图片位置改为在文字下方
        btn.tintColorAdjustsTitleAndImage = UIColor.blackColor;
        btn.adjustsImageTintColorAutomatically = NO;
        btn.spacingBetweenImageAndTitle = 10;
        [btn setImage:UIImageMake(img[@"icon"]) forState:UIControlStateNormal];
        [btn setTitle:img[@"name"] forState:UIControlStateNormal];
        btn.titleLabel.font = DYFont(15);
        btn.tag = i;
        [_manContent addSubview:btn];

        [manArr addObject:btn];
        
        [btn addTarget:self action:@selector(myOrderBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
        
    // 实现masonry水平固定间隔方法
    [manArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:5 leadSpacing:0 tailSpacing:0];
    
    // 设置array的垂直方向的约束
    [manArr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_manContent).mas_offset(0);
    }];
     
//    [_manContent setupAutoContentSizeWithRightView:manArr.lastObject rightMargin:0];
}

- (void)setModel:(UserInfo *)model {

}

- (void)myOrderBtnClick:(UIButton *)sender {
    if ([_delegate respondsToSelector:@selector(mineOrderDidSelectAtIndex:)]) {
        [_delegate mineOrderDidSelectAtIndex:sender.tag];
    }
}
 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
